package com.ruoyi.web.controller.equipment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.base.BaseShop;
import com.ruoyi.system.domain.equipment.EquipmentBook;
import com.ruoyi.system.domain.equipment.EquipmentBookDTO;
import com.ruoyi.system.mapper.BaseShopMapper;
import com.ruoyi.system.mapper.SysDeptMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IEquipmentBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备台账Controller
 *
 * @author ruoyi
 * @date 2023-03-01
 */
@Api(tags = "设备台账api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/equipment/book" )
public class EquipmentBookController extends BaseController {

    private final IEquipmentBookService iEquipmentBookService;


    /**
     * 查询设备台账列表
     */
    @ApiOperation(value = "查询设备台账列表")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentBook equipmentBook)
    {
        startPage();
        List<EquipmentBookDTO> list = iEquipmentBookService.getList(equipmentBook);
        return getDataTable(list);
    }

    /**
     * 导出设备台账列表
     */
    @Log(title = "设备台账" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(EquipmentBook equipmentBook) {
        LambdaQueryWrapper<EquipmentBook> lqw = new LambdaQueryWrapper<EquipmentBook>(equipmentBook);
        List<EquipmentBook> list = iEquipmentBookService.list(lqw);
        ExcelUtil<EquipmentBook> util = new ExcelUtil<EquipmentBook>(EquipmentBook. class);
        return util.exportExcel(list, "book" );
    }

    /**
     * 获取设备台账详细信息
     */
    @ApiOperation(value = "获取设备台账详细信息")
    @GetMapping(value = "/{bookId}" )
    public AjaxResult getInfo(@PathVariable("bookId" ) Long bookId) {
        return AjaxResult.success(iEquipmentBookService.getInfoById(bookId));
    }


    /**
     * 新增设备台账
     */
    @ApiOperation(value = "新增设备台账")
    @Log(title = "设备台账" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentBook equipmentBook) {
        AjaxResult ajaxResult = iEquipmentBookService.addSbtz(equipmentBook);
        return ajaxResult;
    }

    /**
     * 修改设备台账
     */
    @ApiOperation(value = "修改设备台账")
    @Log(title = "设备台账" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentBook equipmentBook) {
        AjaxResult ajaxResult = iEquipmentBookService.updateSbtz(equipmentBook);
        return ajaxResult;
    }


    /**
     * 删除设备台账
     */
    @ApiOperation(value = "删除设备台账")
    @Log(title = "设备台账" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{bookIds}" )
    public AjaxResult remove(@PathVariable Long[] bookIds) {
        return toAjax(iEquipmentBookService.removeByIds(Arrays.asList(bookIds)) ? 1 : 0);
    }
}
